using Godot;
using System;

public partial class LevelStartScreen : Node2D
{
    [Signal]
    public delegate void OnScreenEndEventHandler();

    AnimationPlayer animationPlayer;
    CanvasLayer canvasLayer;
    Control root;
    Label label;

    public override void _Ready()
    {
        base._Ready();
        root = GetNode<Control>("CanvasLayer/Root");
        canvasLayer = GetNode<CanvasLayer>("CanvasLayer");
        label = GetNode<Label>("CanvasLayer/Root/MarginContainer/Label");
        animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
        animationPlayer.AnimationFinished += OnAnimationFinishedHandler;
    }

    private void OnAnimationFinishedHandler(StringName animName)
    {
        canvasLayer.Hide();
        EmitSignal(SignalName.OnScreenEnd);
    }


    public void ShowScreen(string title)
    {
        AudioManager.PauseBgm();
        label.Text = title;
        canvasLayer.Show();
        AudioManager.PlayEffect("start_title");
        animationPlayer.Play("fade_out");
    }
}
